import time
from Bio import Entrez, SeqIO
db = 'nucest'

idfile = 'id.txt'
outfile = 'data.txt'
step = 500

ids = open(idfile).read().split('\n')

while ids:
  temp_ids, ids = ids[:step], ids[step:]
  gi_str = ','.join(temp_ids)
  #print gi_str
  handle = Entrez.efetch(db=db, id=gi_str, rettype="fasta")
  records = SeqIO.parse(handle, "fasta")
  for record in records:
    print record.format('fasta')
  
  time.sleep(5)
